package tchk.xyz.lingyuntutorminiprogram.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import tchk.xyz.lingyuntutorminiprogram.dto.ComplaintDTO;
import tchk.xyz.lingyuntutorminiprogram.dto.ComplaintHandleDTO;
import tchk.xyz.lingyuntutorminiprogram.service.IComplaintService;
import tchk.xyz.lingyuntutorminiprogram.utils.Result;

@RestController
@RequestMapping("/api/admin/complaint")
@PreAuthorize("hasAuthority('admin:complaint:manage')")
public class ComplaintController {

    @Autowired
    private IComplaintService complaintService;

    @GetMapping("/list")
    public Result<IPage<ComplaintDTO>> getList(@RequestParam(defaultValue = "1") long current,
                                               @RequestParam(defaultValue = "10") long size,
                                               @RequestParam(required = false) String status) {
        Page<ComplaintDTO> page = new Page<>(current, size);
        return Result.success(complaintService.getComplaintList(page, status));
    }

    @PutMapping("/handle")
    public Result<Void> handleComplaint(@RequestBody ComplaintHandleDTO handleDTO) {
        complaintService.handleComplaint(handleDTO);
        return Result.success();
    }
}